package com.random.fox.whatspay.bean;

import com.random.fox.whatspay.greendao.DaoSession;
import com.random.fox.whatspay.greendao.dao.AccountDao;
import com.random.fox.whatspay.greendao.dao.CostDao;

import java.util.Date;

import de.greenrobot.dao.DaoException;

/**
 * Created by 渠 on 2014/9/13.
 */
public class Cost {

    private long id;
    /**
     * 消费时间
     */
    private java.util.Date date;
    /**
     * 金额
     */
    private long cost;
    /**
     * 消费描述
     */
    private String des;

    private long accountId;

    private transient DaoSession daoSession;
    private transient CostDao myDao;

    private Account account;
    private Long account__resolvedKey;

    public Cost() {
        date = new Date();
    }

    public Cost(long id) {
        this.id = id;
        date = new Date();
    }

    public Cost(long id,Date date,long accountId) {
        this.id = id;
        this.accountId = accountId;
        this.date = date;
    }

    public long getAccountId() {
        return accountId;
    }

    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public long getCost() {
        return cost;
    }

    public void setCost(long cost) {
        this.cost = cost;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getCostDao() : null;
    }


    public Account getAccount(){
        long __key = this.accountId;
        if (account__resolvedKey == null || !account__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            AccountDao targetDao = daoSession.getAccountDao();
            Account accountIdNew = targetDao.load(__key);
            synchronized (this) {
                account = accountIdNew;
                account__resolvedKey = __key;
            }
        }
        return account;
    }

    public void setAccount(Account account) {
        if (account == null) {
            throw new DaoException("To-one property 'customerId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.account = account;
            accountId = account.getId();
            account__resolvedKey = accountId;
        }
    }

    public void delete(){
        if (myDao == null){
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    public void update(){
        if (myDao == null){
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    public void refresh(){
        if (myDao == null){
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
}
